//
//  ProjectBidsDetailViewController.m
//  Globalstone
//
//  Created by 刘建峰 on 16/7/18.
//  Copyright © 2016年 yuf. All rights reserved.
//

#import "ProjectBidsDetailViewController.h"

@interface ProjectBidsDetailViewController ()<UITextViewDelegate>
@property (weak, nonatomic) IBOutlet UIView *navView;
@property (weak, nonatomic) IBOutlet UIScrollView *scroView;
@property (weak, nonatomic) IBOutlet UIView *commitPriceView;
@property (weak, nonatomic) IBOutlet UILabel *placeHolder;
@property (weak, nonatomic) IBOutlet UITextView *textView;
@property (weak, nonatomic) IBOutlet UIButton *maskButton;
@property (weak, nonatomic) IBOutlet UIButton *doneButton;
@property (weak, nonatomic) IBOutlet UIButton *commitPriceButton;

@property (weak, nonatomic) IBOutlet UIImageView *companyIMage;
@property (weak, nonatomic) IBOutlet UILabel *bidName;
@property (weak, nonatomic) IBOutlet UILabel *companyName;

@property (weak, nonatomic) IBOutlet UILabel *companyPerson;
@property (weak, nonatomic) IBOutlet UILabel *addressLabel;
@property (weak, nonatomic) IBOutlet UILabel *dateLabel;
@property (weak, nonatomic) IBOutlet UILabel *projectMoney;
@property (weak, nonatomic) IBOutlet UILabel *projectAddress;
@property (weak, nonatomic) IBOutlet UILabel *endTime;
@property (weak, nonatomic) IBOutlet UILabel *serviceRequest;
@property (weak, nonatomic) IBOutlet UILabel *pdfLabel;

@property (weak, nonatomic) IBOutlet UITextField *priceField;

@end

@implementation ProjectBidsDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initViewLayout];
    [self getBidDetail];
    // Do any additional setup after loading the view.
}

- (void)initViewLayout{
    [self adaptiveViewLayout:self.view];
    [self adaptiveViewLayout:self.navView];
    [self adaptiveViewLayout:self.scroView];
    [self adaptiveViewLayout:self.commitPriceView];
    
    _textView.delegate = self;
    
    _scroView.contentSize = flexibleSize(CGSizeMake(0, 505), NO);
    _commitPriceButton.layer.cornerRadius = 4*VerticalRatio();
    _doneButton.layer.cornerRadius =  4*VerticalRatio();
    
    _commitPriceView.layer.cornerRadius = 10*VerticalRatio();
}



- (IBAction)back:(id)sender {
    [self backBtn];
}

#pragma mark === 我要报价

- (IBAction)commitPrice:(id)sender {
    _commitPriceView.hidden = NO;
    _maskButton.hidden = NO;
}

- (IBAction)hidePriceView:(id)sender {
    _commitPriceView.hidden = YES;
    _maskButton.hidden = YES;
}

#pragma mark === 完成报价
- (IBAction)commitPriceHandel:(id)sender {
    _commitPriceView.hidden = YES;
    _maskButton.hidden = YES;
    
    if (![Common getLoginStatus]) {
        [[AppDelegate sharedAppDelegate]ShowLoginPage];
        return ;
    }
    NSMutableDictionary  *dic=[NSMutableDictionary dictionary];
    
    [dic setObject:[Common getLoginInfo][@"userId"] forKey:@"museId"];
    [dic setObject:[Common getLoginInfo][@"userId"] forKey:@"msadMemberId"];
    [dic setObject:[Common getLoginInfo][Key_User_password] forKey:@"musePwd"];
    [dic setObject:[Common getLoginInfo][Key_User_onlineKey] forKey:@"museOnlineTag"];
    
    NSString * lan = [InternationalControl userLanguage];
    if ([lan isEqualToString:@"en"]) {
        [dic setObject:@"2" forKey:@"language"];
    }else{
        [dic setObject:@"1" forKey:@"language"];
    }
    [dic setObject:_bidId forKey:@"mmdeId"];
    self.shareApi.delegate=self;
    [self.shareApi  requestOperationWithDic:dic withPath:GS_saveDoingSupply withHttpType:@"POST" withTag:GS_GS_saveDoingSupply];
}

#pragma mark === 查看附件
- (IBAction)seePdf:(id)sender {
}

#pragma mark === 标书详情
- (void)getBidDetail{
    if (![Common getLoginStatus]) {
        [[AppDelegate sharedAppDelegate]ShowLoginPage];
        return ;
    }
    NSMutableDictionary  *dic=[NSMutableDictionary dictionary];
    
    [dic setObject:[Common getLoginInfo][@"userId"] forKey:@"museId"];
    [dic setObject:[Common getLoginInfo][@"userId"] forKey:@"msadMemberId"];
    [dic setObject:[Common getLoginInfo][Key_User_password] forKey:@"musePwd"];
    [dic setObject:[Common getLoginInfo][Key_User_onlineKey] forKey:@"museOnlineTag"];
    
    NSString * lan = [InternationalControl userLanguage];
    if ([lan isEqualToString:@"en"]) {
        [dic setObject:@"2" forKey:@"language"];
    }else{
        [dic setObject:@"1" forKey:@"language"];
    }
    [dic setObject:_bidId forKey:@"mmdeId"];
    self.shareApi.delegate=self;
    [self.shareApi  requestOperationWithDic:dic withPath:GS_queryDemandDetail withHttpType:@"POST" withTag:GS_GS_queryDemandDetail];

}

#pragma mark - <UITextViewDelegate>


- (void)textViewDidChange:(UITextView *)textView{
    
    if (self.textView.text.length > 0) {
        self.placeHolder.hidden = YES;
    }else{
        self.placeHolder.hidden = NO;
    }
    
}



#pragma   mark---- GetADBanner Request Delegate

-(void)fetchDatabaseFinished:(NSMutableDictionary *)database withTag:(NSInteger)tag{
    if (tag==GS_GS_queryDemandDetail ) {
        
        if (  [[database valueForKey:@"flag"] integerValue]!=1 ) {
            
            [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
            
        }else  {
            NSDictionary * dic = database[@"result"];
            
            _bidName.text = [NSString stringWithFormat:@"%@",dic[@"mmdeName"]];
            _companyPerson.text = [NSString stringWithFormat:@"%@",dic[@"mstoMemberName"]];
            _companyName.text = [NSString stringWithFormat:@"%@",dic[@"mstoName"]];
            
            NSString * image = [NSString stringWithFormat:@"%@",dic[@"mstoImage"]];
            if (image.length>0) {
                [_companyIMage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",IP_Address_ImageDown_Fresh,image]]];
            }
            
           _addressLabel.text = [NSString stringWithFormat:@"%@%@",dic[@"citySysArea"][@"AName"],dic[@"proSysArea"][@"AName"]];
            
            NSString * date = [NSString stringWithFormat:@"%@",dic[@"mmdeCreateTime"]];
            if (date.length>=10) {
                date = [date substringToIndex:10];
            }
            _dateLabel.text = date;
            
            _projectMoney.text = [NSString stringWithFormat:@"%@",dic[@"mmdePrice"]];
            _projectAddress.text = [NSString stringWithFormat:@"%@",dic[@"mmdeCity"]];
            
            NSString * endTime = [NSString stringWithFormat:@"%@",dic[@"mmdeDueTime"]];
            if (endTime.length>=10) {
                endTime = [endTime substringToIndex:10];
            }
            _endTime.text = endTime;
            
            _serviceRequest.text = [NSString stringWithFormat:@"%@",dic[@"mmdeContent"]];
            
            NSString * pdf = [NSString stringWithFormat:@"%@",dic[@"mmdeAttach"]];
            if (pdf.length>=26) {
                pdf = [pdf substringWithRange:NSMakeRange(11, pdf.length-15)];
            }
            _pdfLabel.text = pdf;
        }
    }else if (tag == GS_GS_saveDoingSupply){
    
        if (  [[database valueForKey:@"flag"] integerValue]!=1 ) {
            
            [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
            
        }else  {
          [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
            [self backBtn];
        }
    
    }
}

-(void)fetchDatabaseFailed:(NSError *)error message:(NSString *)message{

        [self dismissWaitDialog];
        
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}




@end
